package com.sojson.config.bean;

import static com.sojson.util.SpringUtil.registerBean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;

/**
 * 手动注册Bean(优先级全场第二高)
 * 
 * @author liu
 * @date 2021-04-28
 */
@Slf4j
@Configuration
public class BaseBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {

    /**
     * 在{@link org.springframework.context.annotation.Condition}之后调用<BR/>
     * 在{@link PropertiesPlaceholder}之前调用<BR/>
     */
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        // 注册bean
        log.info("开始手动注册基础Bean对象！");

        registerBean(registry, ObjectMapper.class);
        log.info("ObjectMapper手动注入成功！");

        log.info("手动注册基础Bean对象结束！");
    }

    /**
     * 在{@link PropertiesPlaceholder}之后调用
     */
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }

}